import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    host: "0.0.0.0",
    cors: true,
    open: true, // 启动时自动打开浏览器 
    https: { // 本地https服务
      key: fs.readFileSync(path.resolve(__dirname, 'localhost+3-key.pem')),
      cert: fs.readFileSync(path.resolve(__dirname, 'localhost+3.pem')),
    },
    proxy: {
      // 使用 proxy 实例
      '/api': {
        target: 'https://uniqueker.top/connect.php', //那个链接咱们只要前面的部分
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
  },
}})
